package com.luobd.bpm.dto;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.activiti.engine.runtime.ProcessInstance;

import java.time.LocalDateTime;
import java.util.Map;

@Data
@ApiModel(description = "流程实例")
public class ProcessInstanceDTO {


    @ApiModelProperty(value = "流程实例id")
    private String id;


    @ApiModelProperty(value = "业务id")
    private String businessKey;

    @ApiModelProperty(value = "流程定义id")
    private String processDefinitionId;

    @ApiModelProperty(value = "流程定义名称")
    private String processDefinitionName;

    @ApiModelProperty(value = "流程定义key")
    private String processDefinitionKey;

    @ApiModelProperty(value = "流程定义描述")
    private String processDefinitionDescription;

    @ApiModelProperty(value = "流程变量")
    private Map<String,Object> processVariables;

    @ApiModelProperty(value = "流程实例是否挂起")
    private Boolean suspended;


    @ApiModelProperty(value = "结束状态")
    private Boolean end;


    @ApiModelProperty(value = "流程实例名称")
    private String name;

    @ApiModelProperty(value = "流程发起人id")
    private String startUserId;

    @ApiModelProperty(value = "流程开始时间")
    private LocalDateTime startTime;


    public ProcessInstanceDTO(){}


    public ProcessInstanceDTO(ProcessInstance instance) {

        this.id = instance.getId();
        this.businessKey = instance.getBusinessKey();
        this.processDefinitionId = instance.getProcessDefinitionId();
        this.processDefinitionName = instance.getProcessDefinitionName();
        this.processDefinitionKey = instance.getProcessDefinitionKey();
        this.processDefinitionDescription = instance.getDescription();
        this.processVariables = instance.getProcessVariables();
        this.suspended = instance.isSuspended();
        this.name = instance.getName();
        this.startUserId = instance.getStartUserId();
        this.startTime = DateUtil.toLocalDateTime(instance.getStartTime());
        this.end = instance.isEnded();

    }






}
